//
//  OrderdetailVC.m
//  Zhiche-Carriage
//
//  Created by 王亚陆 on 16/11/1.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "OrderdetailVC.h"
#import <Masonry.h>
#import "Common.h"
#import "RootViewController.h"
#import "PicCollectionViewCell.h"
#import "BigPhotoView.h"
#import "WKProgressHUD.h"
#import <UIImageView+WebCache.h>
#import "RecordDetailCell.h"


@interface OrderdetailVC ()<UITableViewDelegate,UITableViewDataSource>
{
    Common * com;
    UIImageView * nav;
    UIScrollView * scroll;
    RootViewController * TabBar;

}


@property (nonatomic,strong) UIView * BackView;
@property (nonatomic,strong) UIView * BackView1;
@property (nonatomic,strong) UIView * BackView2;
@property (nonatomic,strong) UIView * BackView3;
@property (nonatomic,strong) UIView * BackView4;
@property (nonatomic,strong) UIView * BackView5;
@property (nonatomic,strong) UITableView *tableView;

//@property (nonatomic,strong) UICollectionView *collectionView;
@property (nonatomic,strong) NSMutableArray *imageArray;//图片数组
@property (nonatomic,strong) NSMutableArray *imgArray;
@property (nonatomic,strong) NSMutableDictionary *countDictionry;


@end
@implementation OrderdetailVC


- (instancetype)init

{
    self = [super init];
    if (self) {
        
        self.orderID = [[NSString alloc]init];
        
    }
    return self;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createNav];
    TabBar = [RootViewController defaultsTabBar];
    [TabBar setTabBarHidden:YES];

    self.imageArray = [NSMutableArray array];
    self.imgArray = [NSMutableArray array];
    self.countDictionry = [NSMutableDictionary dictionary];

    [self createScroll];
    
    [self initDataSource];
    
}


-(void)initDataSource
{
    NSString *string = [NSString stringWithFormat:@"%@/%@",mission_detail,self.orderID];
    
    [Common requestWithUrlString:string contentType:application_json finished:^(id responseObj) {
        
        if ([responseObj[@"success"] boolValue]) {
            
            NSMutableDictionary * dic = responseObj[@"data"];
            
            [self createBackView1:dic];
            
            if (_number != 0) {
                //显示司机信息
                
                [self cteateDriverInfo:dic];
                
            }
          
            [self createBackView2:dic];
            [self createBackView3:dic];
            [self createBackView4:dic];
//            [self createBackView5:dic];
            
            if ([dic[@"deliverPics"] isEqual:[NSNull null]]) {
                
            } else {
                
                if ([dic[@"deliverPics"] count] > 0) {
                    
                    for (int i = 0; i < [dic[@"deliverPics"] count]; i ++) {
                        [self.imageArray addObject:dic[@"deliverPics"][i][@"picKey"]];
                    }
                    
                    [self.countDictionry setObject:dic[@"deliverPics"] forKey:@"单据照片"];

                }
                
            }
            
            
        
            if ([dic[@"damageAttach"] isEqual:[NSNull null]]) {
                
            } else {
                
                if ([dic[@"damageAttach"] count] > 0) {
                    [self.countDictionry setObject:dic[@"damageAttach"] forKey:@"带伤照片"];
                    
                }
            }
            
            if ([dic[@"accidentPics"] isEqual:[NSNull null]]) {
                
            } else {
                
                if ([dic[@"accidentPics"] count] > 0) {
                    [self.countDictionry setObject:dic[@"accidentPics"] forKey:@"事故照片"];
                    
                }
            }
            
            
            if ([[self.countDictionry allKeys] count] > 0) {
                
                
                if (_number != 0) {
                    scroll.contentSize = CGSizeMake(Main_Width, Main_height*1.4 + [[self.countDictionry allKeys] count] * 148 *kHeight);
                    _BackView.frame = CGRectMake(0, 0, Main_Width, Main_height*1.4 + [[self.countDictionry allKeys] count] * 148 *kHeight);
                } else {
                    scroll.contentSize = CGSizeMake(Main_Width, Main_height*1.2 + [[self.countDictionry allKeys] count] * 148 *kHeight);
                    _BackView.frame = CGRectMake(0, 0, Main_Width, Main_height*1.2 + [[self.countDictionry allKeys] count] * 148 *kHeight);
                }
                
            
                
                [self initTableView];
             
                
                if ([[dic allKeys] containsObject:@"description"]) {
                    
                    if ([dic[@"description"] isEqual:[NSNull null]] || [dic[@"description"] isEqualToString:@""]) {
                        
                    } else {
                        
                        
                            scroll.contentSize = CGSizeMake(Main_Width, Main_height*1.6 + [[self.countDictionry allKeys] count] * 148 *kHeight);
                            _BackView.frame = CGRectMake(0, 0, Main_Width, Main_height*1.6 + [[self.countDictionry allKeys] count] * 148 *kHeight);
                            
                        
                        [self createBackView6:dic];


                    }
                    
                }
                
                
            }
            
            
            
        } else {
            //获取失败信息
            [WKProgressHUD popMessage:responseObj[@"message"] inView:self.view duration:1.5 animated:YES];
            
        }
        
        
    } failed:^(NSString *errorMsg) {
        NSLog(@"%@",errorMsg);
        
    }];

}

-(void)createNav{
    
    nav = [self createNav:@"运单详情"];
    [self.view addSubview:nav];

}


-(void)createScroll{
    
    scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, Main_Width,Main_height-64*kHeight)];
    scroll.backgroundColor = GrayColor;
    scroll.contentOffset = CGPointMake(0, 0);
    scroll.contentSize = CGSizeMake(Main_Width, Main_height*1.35);
    self.automaticallyAdjustsScrollViewInsets =NO;
    scroll.bounces = NO;
    //隐藏横向、纵向的滚动条
    scroll.showsHorizontalScrollIndicator = NO;
    scroll.showsVerticalScrollIndicator = NO;
    scroll.delegate = self;
    scroll.minimumZoomScale = 1.0;
    scroll.maximumZoomScale = 3.0;
    [self.view addSubview:scroll];
    
    [scroll mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(nav.mas_bottom).with.offset(0*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, Main_height-64));
    }];
    //设置scrollView的内容视图
    _BackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Main_Width, Main_height*1.35)];
    _BackView.backgroundColor = GrayColor;
    [scroll addSubview:_BackView];
    
}

-(void)createBackView1:(NSMutableDictionary*)dic{
    
    _BackView1 = [[UIView alloc]init];
    _BackView1.backgroundColor = WhiteColor;
    [_BackView addSubview:_BackView1];
    [_BackView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView.mas_left);
        make.centerY.mas_equalTo(_BackView.mas_top).with.offset(21.5*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 43*kHeight));
    }];
    
    NSString * ordercode = [NSString stringWithFormat:@"运单号：%@",dic[@"orderCode"]];
    UILabel * label = [self createUIlabel:ordercode andFont:FontOfSize12 andColor:littleBlackColor];
    [_BackView1 addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView1.mas_left).with.offset(18*kWidth);
        make.centerY.mas_equalTo(_BackView1.mas_top).with.offset(21.5*kHeight);
    }];

}


-(void)cteateDriverInfo:(NSMutableDictionary *)dic
{
    UIView *driverInfoV = [[UIView alloc]init];
    driverInfoV.backgroundColor = WhiteColor;
    [_BackView addSubview:driverInfoV];
    [driverInfoV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(48 * kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 103 *kHeight));

    }];
    
 
  UILabel * CarModel = [self createUIlabel:@"司机信息" andFont:FontOfSize14 andColor:BlackTitleColor];
    [driverInfoV addSubview:CarModel];
    [CarModel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(18 * kHeight);
        make.height.mas_equalTo(43 * kHeight);
        make.width.mas_equalTo(200);
        
    }];
    
    
    UIView *viewline = [[UIView alloc]init];
    [driverInfoV addSubview:viewline];
    
    [viewline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(CarModel.mas_bottom).with.offset(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];
    viewline.backgroundColor = LineGrayColor;
    
    UILabel * label1 = [self createUIlabel:@"姓名:" andFont:FontOfSize12 andColor:littleBlackColor];
    [driverInfoV addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(viewline.mas_bottom).offset(0);
        make.left.mas_equalTo(18 *kHeight);
        make.size.mas_equalTo(CGSizeMake(40 * kHeight, 30 * kHeight));
    }];
    
    
    UIView *viewline1 = [[UIView alloc]init];
    [driverInfoV addSubview:viewline1];
    
    [viewline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(label1.mas_bottom).with.offset(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];
    viewline1.backgroundColor = LineGrayColor;

    

     UILabel * label2 = [self createUIlabel:@"电话:" andFont:FontOfSize12 andColor:littleBlackColor];
    [driverInfoV addSubview:label2];
    
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(label1.mas_bottom).offset(0);
        make.left.mas_equalTo(18 * kHeight);
        make.size.mas_equalTo(CGSizeMake(40 * kHeight, 30 * kHeight));
    }];

   
      UILabel * driverName = [self createUIlabel:[NSString stringWithFormat:@"%@",dic[@"driverName"]] andFont:FontOfSize12 andColor:littleBlackColor];
    [driverInfoV addSubview:driverName];
    [driverName mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(label1.mas_right).offset(0);
        make.centerY.mas_equalTo(label1);
    }];
    
    
    UILabel * driverPhone = [self createUIlabel:[NSString stringWithFormat:@"%@",dic[@"driverPhone"]] andFont:FontOfSize12 andColor:littleBlackColor];
    [driverInfoV addSubview:driverPhone];
    [driverPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(label1.mas_right).offset(0);
        make.centerY.mas_equalTo(label2);
    }];
    
    
}


-(void)createBackView2:(NSMutableDictionary*)dic{
    
    CGFloat h = 0;
    if (_number != 0) {
        h = 155 * kHeight;
    } else {
        h = 48 * kHeight;
    }
    
    _BackView2 = [[UIView alloc]init];
    _BackView2.backgroundColor = WhiteColor;
    [_BackView addSubview:_BackView2];
    [_BackView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView.mas_left);
        make.top.mas_equalTo(h);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 255 *kHeight));
    }];
    
  

    
    UILabel * CarModel = [self createUIlabel:@"地址" andFont:FontOfSize14 andColor:BlackTitleColor];
    [_BackView2 addSubview:CarModel];
    [CarModel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView2.mas_left).with.offset(18*kWidth);
        make.centerY.mas_equalTo(_BackView2.mas_top).with.offset(21.5*kHeight);
    }];
    
    UIView * viewline = [[UIView alloc]init];
    viewline.backgroundColor = LineGrayColor;
    [_BackView2 addSubview:viewline];
    [viewline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_BackView2.mas_top).with.offset(43*kHeight);
        make.left.mas_equalTo(_BackView2.mas_left);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];
    UIView * viewSline = [[UIView alloc]init];
    viewSline.backgroundColor = LineGrayColor;
    [_BackView2 addSubview:viewSline];
    
    

    UILabel * cityName = [self createUIlabel:[NSString stringWithFormat:@"%@",dic[@"departAddr"]] andFont:FontOfSize12 andColor:littleBlackColor];
     UILabel * address = [self createUIlabel:[NSString stringWithFormat:@"%@",dic[@"departAddress"]] andFont:FontOfSize12 andColor:littleBlackColor];
    UIImageView * SmallImage = [[UIImageView alloc]init];
    SmallImage.image = [UIImage imageNamed:@"Address_Cell_fache"];
    
    [_BackView2 addSubview:cityName];
    [_BackView2 addSubview:address];
    [_BackView2 addSubview:SmallImage];
    [cityName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(SmallImage.mas_right).with.offset(16*kWidth);
        make.centerY.mas_equalTo(viewline.mas_top).with.offset(21.5*kHeight);
    }];
    [address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(SmallImage.mas_right).with.offset(16*kWidth);
        make.centerY.mas_equalTo(cityName.mas_centerY).with.offset(21.5*kHeight);
    }];
    [viewSline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(cityName.mas_top);
        make.left.mas_equalTo(_BackView2.mas_left).with.offset(40*kWidth);
        make.width.mas_equalTo(0.5*kHeight);
        make.bottom.mas_equalTo(address.mas_bottom);
    }];
    [SmallImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView2.mas_left).with.offset(20*kWidth);
        make.centerY.mas_equalTo(viewSline.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(12*kWidth, 16*kHeight));
    }];

    
    UIImageView * viewline0 = [[UIImageView alloc]init];
    
    viewline0.backgroundColor = LineGrayColor;
    [_BackView2 addSubview:viewline0];
    [viewline0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(viewSline.mas_bottom).with.offset(19*kHeight);
        make.left.mas_equalTo(_BackView2.mas_left).with.offset(20*kWidth);
        make.size.mas_equalTo(CGSizeMake(Main_Width-40*kWidth, 0.5*kHeight));
    }];
    
    
    UIView * viewSline1 = [[UIView alloc]init];
    viewSline1.backgroundColor = LineGrayColor;
    [_BackView2 addSubview:viewSline1];
    


    UILabel * cityName1 = [self createUIlabel:[NSString stringWithFormat:@"%@",dic[@"arrivalAddr"]] andFont:FontOfSize12 andColor:littleBlackColor];
    UILabel * address1 = [self createUIlabel:[NSString stringWithFormat:@"%@",dic[@"arrivalAddress"]] andFont:FontOfSize12 andColor:littleBlackColor];
    address1.numberOfLines = 2;
    UILabel * iPhone1 = [self createUIlabel:[NSString stringWithFormat:@"%@ %@  ",dic[@"arrivalContact"],dic[@"arrivalPhone"]] andFont:FontOfSize12 andColor:littleBlackColor];
    UIImageView * SmallImage1 = [[UIImageView alloc]init];
//    SmallImage1.backgroundColor = [UIColor cyanColor];
    SmallImage1.image = [UIImage imageNamed:@"Address_Cell_shouche"];
    [_BackView2 addSubview:cityName1];
    [_BackView2 addSubview:address1];
    [_BackView2 addSubview:SmallImage1];
    [_BackView2 addSubview:iPhone1];
    [cityName1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(SmallImage1.mas_right).with.offset(16*kWidth);
        make.centerY.mas_equalTo(viewline0.mas_top).with.offset(21.5*kHeight);
    }];
    [address1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(SmallImage1.mas_right).with.offset(16*kWidth);
        make.centerY.mas_equalTo(cityName1.mas_centerY).with.offset(21.5*kHeight);
        make.width.mas_equalTo(Main_Width*0.75);

    }];
    [iPhone1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(SmallImage1.mas_right).with.offset(16*kWidth);
        make.centerY.mas_equalTo(address1.mas_centerY).with.offset(21.5*kHeight);
    }];

    
    [viewSline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(cityName1.mas_top);
        make.left.mas_equalTo(_BackView2.mas_left).with.offset(40*kWidth);
        make.width.mas_equalTo(0.5*kHeight);
        make.bottom.mas_equalTo(iPhone1.mas_bottom);
    }];

    [SmallImage1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView2.mas_left).with.offset(20*kWidth);
        make.centerY.mas_equalTo(viewSline1.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(12*kWidth, 16*kHeight));
    }];
    
    UIView * viewline1 = [[UIView alloc]init];
    viewline1.backgroundColor = LineGrayColor;
    [_BackView2 addSubview:viewline1];
    [viewline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(viewSline1.mas_bottom).with.offset(14*kHeight);
        make.left.mas_equalTo(_BackView2.mas_left);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];

    
    //    "data": {
    //        "id": 113,
    //        "orderCode": "0171010096/JYGA2011",
    //        "orderTime": "2016-11-03 07:47:00",
    //        "status": 10,
    //        "statusText": "在途",
    //        "departProvince": "湖北省",
    //        "departCity": "武汉市",
    //        "departCounty": "",
    //        "departAddress": "武汉市硚口区利济南路",
    //        "arrivalProvince": "湖北省",
    //        "arrivalCity": "武汉市",
    //        "arrivalCounty": "",
    //        "arrivalAddress": "武汉市硚口区利济南路",
    //        "arrivalContact": "老王",
    //        "arrivalPhone": "010-88888888",
    //        "orderPrice": 1333.50,
    //        "customerRemark": "没有说明",

    
    UIImageView * image1 = [[UIImageView alloc]init];
    image1.image = [UIImage imageNamed:@"下单时间"];
    [_BackView2 addSubview:image1];
    [image1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(viewline1.mas_bottom).with.offset(15*kHeight);
        make.left.equalTo(_BackView2.mas_left).with.offset(20*kWidth);
    }];

    UILabel * order1 = [self createUIlabel:@"下单时间" andFont:FontOfSize12 andColor:littleBlackColor];
    [_BackView2 addSubview:order1];
    [order1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(image1.mas_centerY);
//        make.left.equalTo(image1.mas_right).with.offset(10*kWidth);
        make.left.mas_equalTo(cityName.mas_left);
    }];
    
    UILabel * ordertime = [self createUIlabel:[NSString stringWithFormat:@" %@",dic[@"orderTime"]] andFont:FontOfSize12 andColor:littleBlackColor];
    [_BackView2 addSubview:ordertime];
    [ordertime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(order1.mas_centerY);
        make.left.equalTo(order1.mas_right);
    }];
    
    
    UIView * viewline2 = [[UIView alloc]init];
    viewline2.backgroundColor = LineGrayColor;
    [_BackView2 addSubview:viewline2];
    [viewline2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(image1.mas_bottom).with.offset(10*kHeight);
        make.left.mas_equalTo(_BackView2.mas_left);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];
    
    
    
    UIImageView * image2 = [[UIImageView alloc]init];
    image2.image = [UIImage imageNamed:@"icon_infor_Mileage_imges"];
    [_BackView2 addSubview:image2];
    [image2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(viewline2.mas_bottom).with.offset(15*kHeight);
        make.left.equalTo(_BackView2.mas_left).with.offset(20*kWidth);
    }];
    
    UILabel * distance = [self createUIlabel:@"公里数" andFont:FontOfSize12 andColor:littleBlackColor];
    [_BackView2 addSubview:distance];
    [distance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(image2.mas_centerY);
//        make.left.equalTo(image2.mas_right).with.offset(10*kWidth);
        make.right.mas_equalTo(order1.mas_right);

    }];
    
    UILabel * distanceLabel = [self createUIlabel:[NSString stringWithFormat:@" %.2fkm",[dic[@"distance"] floatValue]] andFont:FontOfSize12 andColor:littleBlackColor];
    [_BackView2 addSubview:distanceLabel];
    [distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(image2.mas_centerY);
        make.left.equalTo(distance.mas_right);
    }];

    
    

}
-(void)createBackView3:(NSMutableDictionary*)dic{
    
    _BackView3 = [[UIView alloc]init];
    _BackView3.backgroundColor = WhiteColor;
    [_BackView addSubview:_BackView3];
    [_BackView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView.mas_left);
        make.top.mas_equalTo(_BackView2.mas_bottom).with.offset(5*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 235*kHeight));
    }];

    UILabel * CarModel = [self createUIlabel:@"车辆信息" andFont:FontOfSize14 andColor:BlackTitleColor];
    [_BackView3 addSubview:CarModel];
    [CarModel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView3.mas_left).with.offset(18*kWidth);
        make.centerY.mas_equalTo(_BackView3.mas_top).with.offset(21.5*kHeight);
    }];
    
    UIView * viewline = [[UIView alloc]init];
    viewline.backgroundColor = LineGrayColor;
    [_BackView3 addSubview:viewline];
    [viewline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_BackView3.mas_top).with.offset(43*kHeight);
        make.left.mas_equalTo(_BackView3.mas_left);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];
    

    UILabel * label1 = [self createUIlabel:@"底盘号：" andFont:FontOfSize12 andColor:BtnTitleColor];

    UILabel * label2 = [self createUIlabel:@"货物说明：" andFont:FontOfSize12 andColor:BtnTitleColor];
    UILabel * label3 = [self createUIlabel:@"分类：" andFont:FontOfSize12 andColor:BtnTitleColor];
    UILabel * label4 = [self createUIlabel:@"车型代码：" andFont:FontOfSize12 andColor:BtnTitleColor];
    label1.textAlignment = NSTextAlignmentRight;
    label2.textAlignment = NSTextAlignmentRight;
    label3.textAlignment = NSTextAlignmentRight;
    label4.textAlignment = NSTextAlignmentRight;

    [_BackView3 addSubview:label1];
    [_BackView3 addSubview:label2];
    [_BackView3 addSubview:label3];
    [_BackView3 addSubview:label4];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(viewline.mas_bottom).with.offset(19*kHeight);
        make.right.mas_equalTo(_BackView3.mas_left).with.offset(80*kWidth);
    }];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label1.mas_centerY).with.offset(48*kHeight);
        make.right.mas_equalTo(_BackView3.mas_left).with.offset(80*kWidth);
    }];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label2.mas_centerY).with.offset(48*kHeight);
        make.right.mas_equalTo(_BackView3.mas_left).with.offset(80*kWidth);
    }];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label3.mas_centerY).with.offset(48*kHeight);
        make.right.mas_equalTo(_BackView3.mas_left).with.offset(80*kWidth);
    }];
    
    
    //        "dWaybillVehicle": [
    //                            {
    //                                "id": 44,
    //                                "waybillId": 113,
    //                                "vehicleTypeId": 8,
    //                                "vehicleTypeCode": "DYDSAUQTW11AH0W002",
    //                                "vehicleTypeName": "全顺V348短轴v柴",
    //                                "vehicleVin": "11111111111111111",
    //                                "vehicleDesc": "联邦快递订V348全顺短轴中低顶（轻型国五）玻璃窗7座物流车",
    //                                "vehicleNum": 1,
    //                                "vehicleUnit": "辆"
    //                            }
    //                            ],
    //

    NSMutableDictionary * newdic = [[NSMutableDictionary alloc]init];
    if ([dic[@"dWaybillVehicle"] count]>0) {
        newdic = dic[@"dWaybillVehicle"][0];

    }
    UILabel * rightlabel1 = [self createUIlabel:[NSString stringWithFormat:@"%@",newdic[@"vehicleVin"]] andFont:FontOfSize12 andColor:BtnTitleColor];
    UILabel * rightlabel2 = [[UILabel alloc]init];
    rightlabel2.text = [NSString stringWithFormat:@"%@",newdic[@"vehicleDesc"]];
    rightlabel2.font = Font(FontOfSize12);
    rightlabel2.textColor = BtnTitleColor;
    rightlabel2.numberOfLines = 3;
    UILabel * rightlabel3 = [self createUIlabel:[NSString stringWithFormat:@"%@",newdic[@"vehicleTypeName"]] andFont:FontOfSize12 andColor:BtnTitleColor];
    UILabel * rightlabel4 = [self createUIlabel:[NSString stringWithFormat:@"%@",newdic[@"vehicleTypeCode"]] andFont:FontOfSize12 andColor:BtnTitleColor];
    [_BackView3 addSubview:rightlabel1];
    [_BackView3 addSubview:rightlabel2];
    [_BackView3 addSubview:rightlabel3];
    [_BackView3 addSubview:rightlabel4];
    [rightlabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label1.mas_centerY);
        make.left.mas_equalTo(label1.mas_right).with.offset(5*kWidth);
    }];
    [rightlabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label2.mas_centerY);
        make.left.mas_equalTo(label2.mas_right).with.offset(5*kWidth);
        make.width.mas_equalTo(200*kWidth);
    }];
    [rightlabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label3.mas_centerY);
        make.left.mas_equalTo(label3.mas_right).with.offset(5*kWidth);
    }];
    [rightlabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label4.mas_centerY);
        make.left.mas_equalTo(label4.mas_right).with.offset(5*kWidth);
    }];
    
}
-(void)createBackView4:(NSMutableDictionary*)dic{
    
    
    _BackView4 = [[UIView alloc]init];
    _BackView4.backgroundColor = WhiteColor;
    [_BackView addSubview:_BackView4];
    [_BackView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView.mas_left);
        make.top.mas_equalTo(_BackView3.mas_bottom).with.offset(5*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 105*kHeight));
    }];
    
    UILabel * CarModel = [self createUIlabel:@"备注" andFont:FontOfSize14 andColor:BlackTitleColor];
    [_BackView4 addSubview:CarModel];
    [CarModel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView4.mas_left).with.offset(18*kWidth);
        make.centerY.mas_equalTo(_BackView4.mas_top).with.offset(21.5*kHeight);
    }];
    
    UIView * viewline = [[UIView alloc]init];
    viewline.backgroundColor = LineGrayColor;
    [_BackView4 addSubview:viewline];
    [viewline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_BackView4.mas_top).with.offset(43*kHeight);
        make.left.mas_equalTo(_BackView4.mas_left);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];
    
    
    UILabel * inforlabel = [[UILabel alloc]init];

    inforlabel.text = [NSString stringWithFormat:@"%@",[self backString:dic[@"customerRemark"]]];
    inforlabel.font = Font(FontOfSize12);
    inforlabel.textColor = BtnTitleColor;
    inforlabel.numberOfLines = 3;
    [_BackView4 addSubview:inforlabel];
    [inforlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(viewline.mas_bottom).with.offset(30*kHeight);
        make.left.mas_equalTo(_BackView4.mas_left).with.offset(18*kWidth);
        make.width.mas_equalTo(260*kWidth);
    }];


    
}
-(void)createBackView5:(NSMutableDictionary*)dic{
    
    _BackView5 = [[UIView alloc]init];
    _BackView5.backgroundColor = WhiteColor;
    [_BackView addSubview:_BackView5];
    [_BackView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView.mas_left);
        make.top.mas_equalTo(_BackView4.mas_bottom).with.offset(5*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 92*kHeight));
    }];
    
    UILabel * CarModel = [self createUIlabel:@"费用" andFont:FontOfSize14 andColor:BlackTitleColor];
    [_BackView5 addSubview:CarModel];
    [CarModel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_BackView5.mas_left).with.offset(18*kWidth);
        make.centerY.mas_equalTo(_BackView5.mas_top).with.offset(21.5*kHeight);
    }];
    
    UIView * viewline = [[UIView alloc]init];
    viewline.backgroundColor = LineGrayColor;
    [_BackView5 addSubview:viewline];
    [viewline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_BackView5.mas_top).with.offset(43*kHeight);
        make.left.mas_equalTo(_BackView5.mas_left);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
    }];

    NSString * money = [NSString stringWithFormat:@"￥%.2f",[dic[@"orderPrice"] floatValue]];
    UILabel * moneylabel = [self createUIlabel:money andFont:FontOfSize14 andColor:YellowColor];
    [_BackView5 addSubview:moneylabel];
    [moneylabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_BackView5.mas_right).with.offset(-18*kWidth);
        make.centerY.mas_equalTo(viewline.mas_bottom).with.offset(21.5*kHeight);
    }];
    
}

/*
-(void)initCollectionView
{
    __weak typeof(self) weakSelf = self;
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(100 * kHeight, 100 * kHeight);
    layout.minimumInteritemSpacing = 40 * kHeight;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
    [_BackView addSubview:self.collectionView];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(weakSelf.BackView4.mas_bottom).offset(5 *kHeight);
        make.size.mas_equalTo(CGSizeMake(screenWidth, 200 * kHeight));
        
    }];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    
    //cell注册
    [self.collectionView registerClass:[PicCollectionViewCell class] forCellWithReuseIdentifier:@"PicCollectionViewCell"];
    
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
    
    self.collectionView.backgroundColor = WhiteColor;
    
    
}

#pragma mark UICollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PicCollectionViewCell" forIndexPath:indexPath];
    
//    [cell.heroImageView sd_setImageWithURL:self.imageArray[indexPath.row] placeholderImage:[UIImage imageNamed:@"test"]];
//    
//    [cell.heroImageView sd_setImageWithURL:self.imageArray[indexPath.row] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        
//
//        
//    }];
    
    
//    __block UIActivityIndicatorView *activityIndicator;
    if (self.imageArray.count > 0) {

    [cell.heroImageView sd_setImageWithURL:self.imageArray[indexPath.row] placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
//        if (!activityIndicator)
//        {
//            activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
//            activityIndicator.center = images.center;
//            //把更新UI放到主线程
//            dispatch_async(dispatch_get_main_queue(), ^{
//                [images addSubview:activityIndicator];
//            });
//            
//            [activityIndicator startAnimating];
//        }
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    
        [self.imgArray addObject:image];

    
    }];
    }else{
        cell.heroImageView.image = [UIImage imageNamed:@"car_style"];
        
    }
    
    return cell;
}
//点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (self.imgArray.count == 2) {

    BigPhotoView *bigPhotoView = [[BigPhotoView alloc]initWithFrame:self.view.bounds imageArray:self.imgArray selectPathIndex:indexPath collectionView:self.collectionView];
        [self.view addSubview:bigPhotoView];
    }
}

//头标题尺寸
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(screenWidth, cellHeight);
}

//items偏移量
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(20, 30, 20, 30);
}

//头标题
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];
    
    for (UILabel *view in headerView.subviews) {
        [view removeFromSuperview];
    }
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, 150, headerView.frame.size.height)];
    lable.font = Font(15);
    lable.text = @"单据照片";
    
    [headerView addSubview:lable];
    
    UILabel *lineL = [[UILabel alloc]initWithFrame:CGRectMake(0, cellHeight - 0.5, screenWidth, 0.5)];
    lineL.backgroundColor = LineGrayColor;
    [headerView addSubview:lineL];
    
    
    return headerView;
}

*/


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//text自适应宽高
-(UILabel*)createUIlabel:(NSString *)title andFont:(CGFloat)font andColor:(UIColor *)color{
    
    UILabel * label =[[UILabel alloc]init];
    label.text = title;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = color;
    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:font];CGSize size = [label.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    // 名字的H
    CGFloat nameH = size.height;
    // 名字的W
    CGFloat nameW = size.width;
    
    label.textAlignment = NSTextAlignmentLeft;
    label.frame =CGRectMake(0, 0, nameW, nameH);
    label.font = Font(font)
    return label;
}
-(NSString *)backString:(NSString *)string
{
    //    NSString * str = [NSString stringWithFormat:@"%@",string];
    if ([string isEqual:[NSNull null]]) {
        return @"暂无信息";
    } else {
        return string;
    }
}


-(void)initTableView
{

    __weak typeof(self) weakSelf = self;
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [_BackView addSubview:self.tableView];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(weakSelf.BackView4.mas_bottom).offset(5 *kHeight);
        make.size.mas_equalTo(CGSizeMake(screenWidth, [[self.countDictionry allKeys] count] * 148 *kHeight ) );
    }];
    
    
}

-(void)createBackView6:(NSDictionary *)dic
{
    __weak typeof(self) weakSelf = self;
    
    UIView *view6 = [[UIView alloc]init];
    
    view6.backgroundColor = WhiteColor;
    [_BackView addSubview:view6];
    [view6 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(weakSelf.tableView.mas_bottom).offset(0);
        make.size.mas_equalTo(CGSizeMake(screenWidth,100 * kHeight + cellHeight ));
        
    }];
    
    UILabel *topLabel = [[UILabel alloc]init];
    [view6 addSubview:topLabel];
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(18);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(200, cellHeight));
        
    }];
    
    topLabel.text = @"事故描述";
    topLabel.textColor = BlackTitleColor;
    topLabel.font = Font(14);
    
    UILabel *lineL = [[UILabel alloc]init];
    [view6 addSubview:lineL];
    
    [lineL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(topLabel.mas_bottom).offset(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(screenWidth, 0.5));
        
    }];
    lineL.backgroundColor = LineGrayColor;
    
    UILabel *label = [[UILabel alloc]init];
    [view6 addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(18);
        make.top.mas_equalTo( cellHeight);
        make.size.mas_equalTo(CGSizeMake(screenWidth - 36, 100 * kHeight));
        
    }];
    label.font = Font(12);
    label.text = dic[@"description"];
    label.textColor = carScrollColor;
    label.numberOfLines = 0;
    
    
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    NSArray *arr = [self.countDictionry allKeys];
    return arr.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RecordDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecordDetailCell"];
    if (!cell) {
        cell = [[RecordDetailCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"RecordDetailCell"];
    }
    
    NSMutableArray *imgArr = [NSMutableArray array];
    NSArray *arr = [self.countDictionry allKeys];
    NSString *str = arr[indexPath.section];
    
    for (int i = 0; i < [self.countDictionry[str] count]; i ++) {
        
        [imgArr addObject:self.countDictionry[str][i][@"picKey"] ];
        
    }
    
    
    if (imgArr.count > 0) {
        [cell postValueWith:imgArr];
        
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100 *kHeight;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return cellHeight;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5 * kHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = WhiteColor;
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(18, 0, 200, cellHeight)];
    label.font = Font(14);
    NSArray *arr = [self.countDictionry allKeys];
    label.text = [NSString stringWithFormat:@"%@",arr[section]];
    [view addSubview:label];
    
    
    UILabel *lineL = [[UILabel alloc]initWithFrame:CGRectMake(0, cellHeight - 0.5, screenWidth, 0.5)];
    lineL.backgroundColor = LineGrayColor;
    [view addSubview:lineL];
    
    return view;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = GrayColor;
    
    return view;
}




@end
